#include "processbar.h"

const char* lable = "|/-\\";

// void process()
// {
//   char buffer[NUM];
//   memset(buffer,0,sizeof(buffer));
//   int cnt =0;
//   int n = strlen(lable);
//   buffer[0] = HEAD;
//   while(cnt <= 100)
//   {
//     printf("[%-100s][%d%%][%c]\r",buffer,cnt,lable[cnt%n]);
//     fflush(stdout);
//     buffer[cnt++] = BODY;
//     if(cnt < 100) buffer[cnt] = HEAD;
//     usleep(50000);
//   }
//   printf("\n");
// }

char buffer[NUM] ={0};
void process_flush(double rate)
{
    static int cnt = 0;
    int n = strlen(lable);
    if(rate < 0)
        buffer[0] = HEAD;
    
    //颜色打印
    printf("\033[1;31m[%-100s\033[0m]\003[%.1f%%][%c]\r", buffer, rate, lable[cnt]);
    fflush(stdout);

    buffer[(int)rate] = BODY;
    if ((int)rate < 100)
        buffer[(int)(rate+1)] = HEAD;

    if(rate >= 100.0)
        printf("\n");
    
    cnt++;
    cnt %= n;

}

